<p id="notice"><%= notice %></p>

<h1 style="padding-bottom: 20px;">积分汇总</h1>

<% if current_user.admin? %>
<div class="well">
<%= form_tag count_index_path, method: 'get', class: 'form-horizontal' do |f| %>
<fieldset>

<legend>检索条件</legend>
  <div class="form-group">
    <%= label_tag '机构代码',nil, class: 'col-sm-2 control-label' %>
    <div class="col-sm-3">
      <%= select_tag "master_id", options_for_select([["全部", '']] + Department.where(level: 2).select(:dpname, :id).map {|x| [x.dpname,x.id]}, params[:master_id]), class: 'form-control' %>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-10 col-sm-2">
      <%= submit_tag '查询', class: 'btn btn-primary' %>
    </div>
  </div>
</fieldset>
<% end %>
</div>
<% end %>

<table class="table table-bordered table-hover ">
  <thead>
    <tr>
      <th colspan="8">报表日期<span class="pull-right">单位：万元、分</span></th>
    </tr>
    <tr>
      <th rowspan="2" class="text-center">序号</th>
      <th rowspan="2" class="text-center">机构号</th>
      <% get_types.each do |type| %>
        <th colspan="2" class="text-center"><%= type.name %></th>
      <% end %>
    </tr>
    <tr>
      <th>储蓄存款</th>
      <th>积分值</th>
      <th>储蓄存款</th>
      <th>积分值</th>
      <th>储蓄存款</th>
      <th>积分值</th>
    </tr>
  </thead>

  <tbody>
    <% amount0 = 0.0 %>
    <% amount1 = 0.0 %>
    <% amount2 = 0.0 %>
    <% score0 = 0 %>
    <% score1 = 0 %>
    <% score2 = 0 %>
    <% idx = 0 %>
    <% @scores.map.with_index do |score, i| %>
      <tr class="info">
        <% amount0 += score.amount0/10000.0 %>
        <% amount1 += score.amount1/10000.0 %>
        <% amount2 += score.amount2/10000.0 %>
        <% score0 += score.score0 %>
        <% score1 += score.score1 %>
        <% score2 += score.score2 %>
        <% idx = i + 1 %>
        <td><%= i + 1 %></td>
        <td><%= score.dpname %></td>
        <td><%= score.amount0/10000.0 %></td>
        <td><%= score.score0 %></td>
        <td><%= score.amount1/10000.0 %></td>
        <td><%= score.score1 %></td>
        <td><%= score.amount2/10000.0 %></td>
        <td><%= score.score2 %></td>
      </tr>
    <% end %>
    <tr>
      <td><%= idx + 1 %></td>
      <td>合计</td>
      <td><%= amount0 %></td>
      <td><%= score0 %></td>
      <td><%= amount1 %></td>
      <td><%= score1 %></td>
      <td><%= amount2 %></td>
      <td><%= score2 %></td>
    </tr>
  </tbody>
</table>
